package me.firstapp.manage.section;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.common.json.SingleObject;
import me.firstapp.common.module.bbs.JsonSection;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.spi.bbs.SectionService;

@Controller
@RequestMapping(value = "/sectionManage")
public class SectionManagePage extends BaseManage {
	@Autowired
	private SectionService sectionService;

	@RequestMapping(value = "/sectionList.html", method = RequestMethod.GET)
	public ModelAndView sectionListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("section/sectionList", modelMap);
	}

	@RequestMapping(value = "/sectionAdd.html", method = RequestMethod.GET)
	public ModelAndView sectionAddView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("section/sectionAdd", modelMap);
	}

	@RequestMapping(value = "/sectionUpdate.html", method = RequestMethod.GET)
	public ModelAndView sectionUpdateView(Long sectionId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		SingleObject<JsonSection> result = sectionService.findById(sectionId);
		modelMap.put("section", result.getObject());
		modelMap.put("sectionId", sectionId);
		return new ModelAndView("section/sectionUpdate", modelMap);
	}
}
